package com.cssy.yd.logic.web;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cssy.base.web.BaseController;
import com.cssy.yd.logic.entity.PoGatherReportFormsDO;
import com.cssy.yd.logic.service.ILogicPoService;
import com.cssy.yd.logic.util.SqlUtil;
import com.cssy.yd.logic.vo.LogicWhAffVO;
import com.plat.helper.JqGridHandler;
import com.plat.helper.SearchConditions;
import com.plat.helper.SearchResult;
import com.plat.util.DateUtils;
import com.plat.util.ExcelUtil;
import com.plat.util.json.OutJsonGrid;

@Controller
@RequestMapping("/yd/logic/poGatherReportForms")
public class PoGatherReportFormsController extends BaseController<PoGatherReportFormsDO>{
	private static final String MANAGER = "/yd/logic/poGatherReportforms/PoGatherManager";// 列表页面

	@Resource(name="logicPoService")
	private ILogicPoService logicPoService;
	
	@Override
	public String manager(HttpServletRequest request, Model model)
			throws Exception {
		return MANAGER;
	}

	@Override
	public void list(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		JqGridHandler hander=new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.getWheres(scs);
		String wlCode = hander.getQueryValue("wlCode");
		String wlName = hander.getQueryValue("wlName");
		Map<String, Object> map = new HashMap<String, Object>();
		if(!"".equals(wlCode)){
			map.put("wlCode", wlCode);
		}
		if(!"".equals(wlName)){
			map.put("wlName", wlName);
		}
		map.put("limitClause", scs.getLimitClause());
		SearchResult result = logicPoService.findPoGatherByExample(map);
		List<PoGatherReportFormsDO> list = result.getResults();
		OutJsonGrid out = new OutJsonGrid(result);
		out.printJSon(response);
		
	}

	@Override
	public String operationForm(HttpServletRequest request, String id,
			String flag, Model model) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> save(HttpServletRequest request,
			PoGatherReportFormsDO curAP, BindingResult result, Model model)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> delete(HttpServletRequest request,
			HttpServletResponse response, Model model) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	
	/**
	 * 采购汇总报表
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/exportExcelPoGather")
	public void exportExcelPoGather(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		JqGridHandler hander=new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.setFilters(new String(request.getParameter("filters").getBytes(
				"ISO-8859-1"), "UTF-8"));
		hander.getWheres(scs);
		String wlCode = hander.getQueryValue("wlCode");
		String wlName = hander.getQueryValue("wlName");
		Map<String, Object> map = new HashMap<String, Object>();
		if(!"".equals(wlCode)){
			map.put("wlCode", wlCode);
		}
		if(!"".equals(wlName)){
			map.put("wlName", wlName);
		}
		//map.put("limitClause", scs.getLimitClause());
		SearchResult result = logicPoService.findPoGatherByExample(map);
		List<PoGatherReportFormsDO> list = result.getResults();
		ExcelUtil.toExcel(list, "物料编码:wlCode┋物料名称:wlName┋基本单位入库总数:rkCountJquantity┋常用单位入库总数:rkCountQuantity┋物料单价:price┋总金额:sumMoney","采购汇总报表",response);
	}
}
